<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
		<title>二级讨论页</title>
		<link rel="stylesheet" type="text/css" href="../../css/mui.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css">
		<link rel="stylesheet" type="text/css" href="../../css/discuss.css">
		<link rel="stylesheet" href="../../css/CFNetPP_Base.css">
		<link rel="stylesheet" href="../../css/base.css">
		<style>
			.current-discuss-tag {
				line-height: 1em;
				margin: 0;
			}
			.mui-table-view-cell {
				padding: 10px;
			}
			.no-active-cell:active {
				background-color: white;
			}
			.content-p {
				line-height: 1.4em;
			}
			.discuss-img {
				max-width: 100%;
			}
			.img-div {
				text-align: center;
			}
			#commentList {
				margin-top: 10px;
			}
			.touxiang {
				width: 38px;
				height: 38px;
				border-radius: 19px;
			}
			.nameLabel {
				margin-top: 2px;
			}
			.contentDiv {
				text-overflow: -o-ellipsis-lastline;
				overflow: hidden;
				text-overflow: ellipsis;
				display: -webkit-box;
				/*-webkit-line-clamp: 3;*/
				-webkit-box-orient: vertical;
			}
			.timeSpan {
				margin-top: 10px;
			}
			.question_detail {
				background-color: white;
				padding: 10px;
				/*border-bottom: 1px solid #ddd;*/
			}
			.rightSpan {
				margin-left: 20px;
			}
			.user-icon-div {
				width: 38px;
				float: left;
			}
			.dis-tag-img {
				width: 12px;
				margin-right: 4px;
			}
			.dis-content-div {
				margin-left: 48px;
			}
			.top-tag-cell {
				padding: 8px 10px;
			}
			.delete-btn {
				color: #d81e06;
			}
			.yi-dian-zan {
				color: #18b4ed;
			}
			.bottom-none-div {
				height: 45px;
			}
			.huifuImg_span {
				height: 12px;
				line-height: 12px;
				padding-left: 15px;
				background: url(../../image/icon_huifu.png) no-repeat 0px 1px;
				background-size: 12px 12px;
			}
			.delete_btn {
				float: right;
				color: #18b4ed;
				margin-right: 22px;
			}
			.mui-table-view-cell:active {
				background: #fff;
			}
		</style>
	</head>
	<body>
		<div id=" ">
			<div class="  " >
				<ul class="mui-table-view ">
					<li class="mui-table-view-cell">
						<div class="user-icon-div">
							<img class="touxiang" src="../../image/default_user_icon.png" id="img1">
						</div>
						<div class="dis-content-div">
							<label class="nameLabel base_dark_grey base_content_font" id="name"></label>
							<!--提问内容-->
						</div>
						<div class="contentDiv base_dark_grey base_content_font" id="content">
							<!--提问内容-->
						</div>
						<span class="timeSpan base_grey base_content_font" id="stime"></span>
						<span class="timeSpan rightSpan base_grey base_content_font right right_15" > <span class="huifuImg_span " > </span> <span class=" font12 " id="num"> 0</span> </span>
					</li>
				</ul>
			</div>
			<div id="commentList "style="margin-top: 10px;" class="freestudyComment">
				<ul class="mui-table-view "id="list_discus"></ul>
				<div class="noSign" hidden="hidden" id="noData">
					<img src="../../image/icon_img.png" width="60%">
					<p class="font16 top_15 base_dark_grey" >
						暂无回复哦
					</p>
				</div>
				<div class="loadFailure" hidden="hidden" id="noNet">
					<img src="../../image/icon_img01.png" width="60%">
					<p class="" >
						数据加载失败
					</p>
					<p>
						请检查您的网络
					</p>
					<button type="button" class="mui-btn mui-btn-outlined" onclick="RefreshData()">
						重新加载
					</button>
				</div>
				<div id="deleteAlert" class="weui_dialog_confirm" style="display: none;">
					<div class="weui_mask"></div>
					<div class="weui_dialog">
						<div class="weui_dialog_hd">
							<strong class="weui_dialog_title">确定删除此回复？</strong>
						</div>
						<div class="weui_dialog_bd"></div>
						<div class="weui_dialog_ft">
							<a onclick="cleanCancel()" href="#" class="weui_btn_dialog default"  style="color:#18b4ed">取消</a>
							<a onclick="cleanConfirm()" href="#" class="weui_btn_dialog primary"  style="color:#18b4ed">确定</a>
						</div>
					</div>
				</div>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="../../script/jquery.min.js"></script>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script src="../../script/jquery.min.js" type="text/javascript"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script src="../../script/common.js"></script>
	<script src="../../script/timeStampTool.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript">
		var page = 1;
		var row = 10;
		var refreshCount = 0;
		//更新数据条数
		var dataArr = new Array();
		var id = '';
		var img = '';
		var pid = "";
		// 计划id
		var cid = "";
		//课程id
		var chapterid = "";
		//章节id
		//被点击的题目id
		var Itemid = "";
		apiready = function() {
			preData();
			showProgress();
			ReceiveNotifi();
			loadNewData();
			setRefreshHeader();
			setPullUpRefresh();
		};
		function preData() {
			var pageParam = api.pageParam;
			pid = pageParam.pid;
			cid = pageParam.cid;
			chapterid = pageParam.chapterid;
			$('#name').text(api.pageParam.data.username);
			$('#content').html(api.pageParam.data.content);
			$('#stime').text(timestampFormat(api.pageParam.data.ctime));
			var imgStr = HeadPortraitIsNull(api.pageParam.data.userimg);
			document.getElementById("img1").src = imgStr;
		}

		function ReceiveNotifi() {
			api.addEventListener({
				name : 'RefreshDiscusListNotifi'
			}, function(ret, err) {
				loadNewData();
			});
			//添加新的讨论的通知
			api.addEventListener({
				name : 'RefreshAddDiscusListNotifi'
			}, function(ret, err) {
				loadNewData();
			});
			api.addEventListener({
				name : 'RefreshMoccDiscusListNotifi'
			}, function(ret, err) {
				loadNewData();
			});
		}

		//接收通知刷新列表
		function loadNewData() {
			page = 1;
			loadData();
			//停止刷新控件
		}

		//		接收通知
		function loadMoreData() {
			page++;
			loadData();
		}

		function loadData() {
			var param = {
				pid : pid,
				cid : cid,
				vid : chapterid,
				jid : $api.getStorage('cfnetppjxid'),
				uid : $api.getStorage('cfnetppuid'),
				fid : api.pageParam.data.id,
				page : page,
				rows : row,
			};
			cfnetppPOST(url_discussList, param, true, function(data, status) {
				//				alert('1' + JSON.stringify(data))
				//				alert(JSON.stringify(param))
				api.refreshHeaderLoadDone();
				hideProgress();
				if (status == 'success') {
					$('#noNet').hide();
					if (data.code == 200) {
						$('#noData').hide();
						var list = data.json.list;
						if (list != null && list.length > 0) {
							$('#num').text(list.length);
							$('#noData').hide();
							setUI(list, list.length);
						} else {
							$('#num').text(list.length);
							if (page == 1) {
							} else {
								api.toast({
									msg : '暂无数据',
									duration : 2000,
									location : 'bottom'
								});
							}
							$('#list_discus').html('');
						}
					} else if (data.code == 108) {
						$('#num').text('0');
						if (page == 1) {
							$('#list_discus').html('');
						}
					} else {
						if (page == 1) {
							$('#list_discus').html('');
						}
					}
				} else {
					$('#noNet').show();
				}
			});
		}

		//得到数据，显示在ui布局上
		function setUI(data, len) {
			var strUI = '';
			var listArr = new Array();
			for (var i = 0; i < len; i++) {
				var list = data[i];
				listArr.push(list);
				dataArr = listArr;
				var delebtnStr = '';
				if (list.uid == $api.getStorage('cfnetppuid')) {
					delebtnStr = '<span class="top_2 font10  delete_btn" onclick="showAlert(' + list.id + ')">删除</span> '
				} else {
					delebtnStr = ''
				}
				var str = '<li class="mui-table-view-cell mui-media font12 left_30">' + '<img class="mui-media-object mui-pull-left cell_user_icon " src="' + HeadPortraitIsNull(list.picurl) + '" style="display: block;height: 40px">' + '<p class="top_2 font14 fontBold" >' + list.rename + '</p>' + '<div class="secondCommentbody  ">' + '<p class="word-break left_50 font12">' + list.content + '</p>' + '</div>' + '<p class="top_2 font14 fontBold left_45" >' + '<span class="top_2 font10 left_5" >' + timestampFormat(list.ctime) + '</span>' + delebtnStr + '</p>' + '</li>';
				strUI = strUI + str;
			}
			if (page == 1) {
				$('#list_discus').html(strUI);
			} else {
				$('#list_discus').append(strUI);
			}
		}

		function showAlert(id) {
			$('#deleteAlert').show();
			Itemid = id;
		}

		function cleanCancel() {
			$('#deleteAlert').hide();
		}

		//确定
		function cleanConfirm() {
			$('#deleteAlert').hide();
			deleteDiscus(Itemid);
		}

		//删除评论
		function deleteDiscus(id) {
			var param = {
				id : id,
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				pid : pid,
				cid : cid,
				vid : chapterid,
				message : api.pageParam.data.username + '的讨论内容回复'
			};
			cfnetppPOST(url_deleteDiscuss, param, true, function(data, status) {
				hideProgress();
				if (api.pageParam.type == 1) {//mocc
					if ($api.getStorage('cfnetSelectType') == 0) {//学生身份){
						SendBusinessOperationsLogNotifi('讨论列表页', '020', param, param, '', data, 'Mocc课程讨论章节学生删除回复讨论接口', '020-05')
					} else if ($api.getStorage('cfnetSelectType') == 1) {//老师身份
					    SendBusinessOperationsLogNotifi('讨论列表页', '020', param, param, '', data, 'Mocc课程讨论章节老师删除回复讨论接口', '020-10')
					}
				} else {
					if ($api.getStorage('cfnetSelectType') == 0) {//学生身份){
						SendBusinessOperationsLogNotifi('讨论列表页', '032', param, param, '', data, '自由课程讨论章节学生删除回复讨论接口', '032-05')
					} else if ($api.getStorage('cfnetSelectType') == 1) {//老师身份
						SendBusinessOperationsLogNotifi('讨论列表页', '032', param, param, '', data, '自由课程讨论章节老师删除回复讨论接口', '032-10')
					}
				}
				if (status == 'success') {
					if (data.code == 200) {
						ShowToast('删除成功');
						loadNewData();
					} else {
						api.toast({
							msg : '删除失败',
							duration : 2000,
							location : 'bottom'
						});
					}
				} else {
					api.toast({
						msg : '获取数据失败',
						duration : 2000,
						location : 'bottom'
					});
				}
			});
		}
	</script>
</html>